package com.anyou.mall.sho.service.impl;

import java.util.List;

import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.sho.mapper.ShoShopAddressMapper;
import com.anyou.mall.sho.domain.ShoShopAddress;
import com.anyou.mall.sho.service.IShoShopAddressService;

/**
 * 商家退换货地址Service业务层处理
 *
 * @author xq
 * @date 2022-04-15
 */
@Service
public class ShoShopAddressServiceImpl implements IShoShopAddressService
{
    @Autowired
    private ShoShopAddressMapper shoShopAddressMapper;

    /**
     * 查询商家退换货地址
     *
     * @param carPartsShopId 商家退换货地址主键
     * @return 商家退换货地址
     */
    @Override
    public ShoShopAddress selectShoShopAddressByAddressId(Long carPartsShopId)
    {
        return shoShopAddressMapper.selectOne(new LambdaQueryWrapper<ShoShopAddress>()
                .eq(ShoShopAddress::getCarPartsShopId,carPartsShopId));
    }

    /**
     * 查询商家退换货地址列表
     *
     * @param shoShopAddress 商家退换货地址
     * @return 商家退换货地址
     */
    @Override
    public List<ShoShopAddress> selectShoShopAddressList(ShoShopAddress shoShopAddress)
    {
        return shoShopAddressMapper.selectShoShopAddressList(shoShopAddress);
    }

    /**
     * 新增商家退换货地址
     *
     * @param shoShopAddress 商家退换货地址
     * @return 结果
     */
    @Override
    public int insertShoShopAddress(ShoShopAddress shoShopAddress)
    {
        ShoShopAddress addAddress = shoShopAddressMapper.selectOne(new LambdaQueryWrapper<ShoShopAddress>()
                .eq(ShoShopAddress::getCarPartsShopId, shoShopAddress.getCarPartsShopId()));
        if(addAddress==null){
            shoShopAddressMapper.insert(shoShopAddress);
        }else {
            shoShopAddressMapper.updateById(shoShopAddress);
        }
        return 1;
    }

    /**
     * 修改商家退换货地址
     *
     * @param shoShopAddress 商家退换货地址
     * @return 结果
     */
    @Override
    public int updateShoShopAddress(ShoShopAddress shoShopAddress)
    {
        return shoShopAddressMapper.updateShoShopAddress(shoShopAddress);
    }

    /**
     * 批量删除商家退换货地址
     *
     * @param addressIds 需要删除的商家退换货地址主键
     * @return 结果
     */
    @Override
    public int deleteShoShopAddressByAddressIds(Long[] addressIds)
    {
        return shoShopAddressMapper.deleteShoShopAddressByAddressIds(addressIds);
    }

    /**
     * 删除商家退换货地址信息
     *
     * @param addressId 商家退换货地址主键
     * @return 结果
     */
    @Override
    public int deleteShoShopAddressByAddressId(Long addressId)
    {
        return shoShopAddressMapper.deleteShoShopAddressByAddressId(addressId);
    }
}
